package com.example.newproject_overseas.ViewModel

import android.content.Context
import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.navigation.NavHostController
import com.example.newproject_overseas.exception.NetworkExceptionHandler
import com.example.newproject_overseas.model.entity.form.CenobitismForm
import com.example.newproject_overseas.model.entity.form.CenobitismModel
import com.example.newproject_overseas.model.entity.form.CenobitismRequest
import com.example.newproject_overseas.model.entity.form.CenobitismResponse
import com.example.newproject_overseas.model.service.form.CenobitismService
import retrofit2.HttpException

class FormViewModel : ViewModel() {

    private val cenobitismService = CenobitismService.instance()


    suspend fun cenobitismReq(
        navController: NavHostController,
        retData: (form: CenobitismForm) -> Unit
    ){
        val cenobitismModel = CenobitismModel("NODE1")
        val cenobitismReq   = CenobitismRequest(cenobitismModel);
        try {
            val cenobitismResp = cenobitismService.sorbolCenobitism(cenobitismReq)
            if (cenobitismResp.status == 0){
                val model = cenobitismResp.model
                var forms = model.forms
                if(forms.size > 0){

                    retData(forms[0])

//                    if(forms[0].formType == "OCR"){
//                       navController.navigate("UploadCardScreen")
//                   }
                }
                Log.i("forms",forms.toString())
            }
            // 处理正常的响应逻辑
        } catch (e: Exception) {
            NetworkExceptionHandler.handleException(e,navController)
        }
    }




}